﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using pos.entity;

namespace pos
{
    public partial class ParaDealerAdd : Form
    {
        public enum STATE
        {
            add = 1, modify = 2
        }
        private STATE state;
        private t_dealer dealer;
        public t_dealer DEALER
        {
            get { return dealer; }
        }
        public ParaDealerAdd(STATE state, t_dealer dealer)
        {
            this.state = state;
            this.dealer = dealer;

            InitializeComponent();
        }
        private void initText()
        {
            if (state == STATE.modify)
            {

                dealer.showInForm(Controls);
            }
        }
        
        private void cmdSave_Click(object sender, EventArgs e)
        {
            try
            {
                if (state == STATE.add)
                {
                    dealer= new t_dealer();

                    dealer.seqID = 1;

                    dealer.initByForm(this.Controls);
                    dealer.state = t_dealer.NORMAL;
                    dealer.add();
                  
                  //  ListViewTool v = new ListViewTool(listView1);
                  //  t.RowInsert = v.insertRow;
                //    t.ExecDataInsert();
                }
                else
                {


                    dealer = t_dealer.GetBySeqID(dealer.seqID);
                    
                    dealer.initByForm(Controls);
                    dealer.state = t_dealer.NORMAL;
                    dealer.update();


              //      ListViewTool v = new ListViewTool(listView1);
                //    t.RowUpdate = v.updateRow;
                  //  t.ExecDataUpdate(currentRow);
                }
                this.DialogResult = DialogResult.OK;
                this.Close();

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            
        }

        private void cmdCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void ParaDealerAdd_Load(object sender, EventArgs e)
        {
            initText();
        }
    }
}
